<template>
    <rx-layout>
        <div slot="left" width="300">
            <div class="rx-vue-tree-box">
                <div style="padding: 6px 0">
                    <a-button type="primary" @click="selectTemplate" size="small">{{i18n('selectTemplate','选择模板')}}</a-button>
                    <a-button type="primary" @click="expandAll" size="small" style="margin: 0 6px">{{$ti18('rxList.openBtn','展开')   }}</a-button>
                    <a-button type="primary" @click="collapseAll" size="small">{{$ti18('rxList.putAwayBtn','收起')}} </a-button>
                </div>
                <rx-vue-tree
                    :tree-data="treeData"
                    :show-edit="true"
                    label="name"
                    field="id"
                    @rowClick="handSelect"
                    :tree-icon="treeIcon"
                    :foldPeerNode="false"
                    :expandedKeys="expandedKeys"
                    :onlyChildNode="true"
                    :showCheckbox="false"
                    :iconStyle="{fontSize:'13px',backgroundColor:'transparent',color:'#333'}"
                >
                    <div slot="edit" slot-scope="{tree,data}">
                        <div class="btn" v-if="tree.type!='file'" @click="addNode(tree,'directory')"><a-icon type="plus" />{{i18n('createDir','新建目录')}}</div>
                        <div class="btn" v-if="tree.type!='file'" @click="addNode(tree,'file')"><a-icon type="plus" />{{i18n('createFile','新建文件')}}</div>
                        <div class="btn" v-if="tree.id != '0'" @click="editNode(tree)"><a-icon type="edit" />{{$ti18('rxList.editBtn','编辑')}}{{getByName(tree.type)}}</div>
                        <div class="btn del" v-if="tree.id != '0'" @click="deleteNode(tree,data)"><a-icon type="delete" />{{$ti18('rxList.delBtn','删除')}}{{getByName(tree.type)}}</div>
                    </div>
                </rx-vue-tree>
            </div>
        </div>
        <div slot="center">
            <rx-monaco-editor
                v-if="curTree"
                ref="content"
                v-model="content"
                language="java"
                :showFullScreen="false"
                style="height:99%;"
            >
                <template v-slot:monacoeditor>
                    <div>
                        <a-dropdown>
                            <a-menu slot="overlay">
                                <template v-for="(item,index) in variableProjectAry">
                                    <a-menu-item :key="item.value" @click="insertScript(item,'project')"> {{item.label}} </a-menu-item>
                                </template>
                            </a-menu>
                            <a-button style="margin-right: 8px">{{i18n('insertProjectVar','插入项目变量')}}
                                <a-icon type="down"/>
                            </a-button>
                        </a-dropdown>
                        <a-dropdown>
                            <a-menu slot="overlay">
                                <template v-for="(item,index) in variableCustomAry">
                                    <a-menu-item :key="item.value" @click="insertScript(item,'vars')"> {{item.label}} </a-menu-item>
                                </template>
                            </a-menu>
                            <a-button style="margin-right: 8px">{{i18n('insertCustomVar','插入自定义变量')}}
                                <a-icon type="down"/>
                            </a-button>
                        </a-dropdown>
                        <a-dropdown>
                            <a-menu slot="overlay">
                                <template v-for="(item,index) in variableGlobalAry">
                                    <a-menu-item :key="item.value" @click="insertScript(item,'vars')"> {{item.label}} </a-menu-item>
                                </template>
                            </a-menu>
                            <a-button style="margin-right: 8px">{{i18n('insertGlobalVar','插入全局变量')}}
                                <a-icon type="down"/>
                            </a-button>
                        </a-dropdown>
                        <a-button type="primary" @click="btnSaveContent">{{$ti18('rxForm.saveBtn','保存')}}</a-button>
                    </div>
                </template>
            </rx-monaco-editor>
        </div>
    </rx-layout>
</template>

<script>
    import FormCodegenProjectEdit3 from "./FormCodegenProjectEdit3.js";

    export default {
        name: "FormCodegenProjectEdit3",
        mixins:[FormCodegenProjectEdit3],
        methods:{
            i18n(name,text,key){
                return this.$ti18(name,text,"formCodegenProject.edit3",key);
            },
            handleBefore(self, this_){
                var result=this_.getData();
                Object.assign(this_.settingJson,result.data);
                this_.formData.settingJson = JSON.stringify(this_.settingJson);
                this_.$emit("changeForm", this_.formData);
            },
            handleSubmit(self, this_,callback){
                this_.saveContent();
                var result = this_.getData();
                if (!result.success) {
                    this_.$message.warning(result.message);
                    return callback(true);
                }
                Object.assign(this_.settingJson,result.data);
                this_.formData.settingJson = JSON.stringify(this_.settingJson);
                this_.$emit("changeForm", this_.formData);
                callback(false);
            }
        }
    }
</script>

<style scoped>

</style>